package ginutil

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

func NewBasicRouter() *gin.Engine {
	r := gin.Default()
	r.MaxMultipartMemory = MaxMultipartMemory
	//  加载html目录下的所有模板文件
	r.LoadHTMLGlob("html/*")
	//  404
	r.NoRoute(func(c *gin.Context) {
		c.String(http.StatusNotFound, "404 NOT FOUND")
	})
	return r
}
func Response(c *gin.Context, obj interface{}) {
	c.JSON(200, obj)
}

//func DataMapByRequest(c *gin.Context) (dataMap map[string]string, err error) {
//	//必须先解析Form
//	c.Request.ParseForm()
//	dataMap = make(map[string]string)
//	//说明:须post方法,加: 'Content-Type': 'application/x-www-form-urlencoded'
//	for key, valueArray := range c.Request.PostForm {
//		//fmt.Printf("参数 key:%s  -> %v ", key, valueArray)
//		if len(valueArray) > 1 {
//			errMsg := fmt.Sprintf("#ERROR#[%s]参数设置了[%d]次,只能设置一次.", key, len(valueArray))
//			return nil, errors.New(errMsg)
//		}
//		dataMap[key] = c.PostForm(key)
//	}
//	//
//	for key, _ := range c.Request.URL.Query() {
//		dataMap[key] = c.Query(key)
//	}
//
//	return
//}
